define('searchList',['text!../tpl/search-list.html','tool','iscroll','weUi'],function(Template,tool,IScroll){
    var App ={
    	template:Template,
    	mixins: [tool.toor],
    	mounted:function(){
    		window.scrollTo(0,0);
    		this.listType=this.$route.query.type,_this=this;
    		var formList=JSON.parse(sessionStorage.getItem('formList'));
    		function loaderScroll(){
    			_this.oIscoll=new IScroll('#list_warp',{mouseWheel: true,topOffset:10});
    			_this.oIscoll.on('scrollEnd', function () {
    				if ((this.y - this.maxScrollY) == 0) {  
    					    _this.page+=1;
		                    _this.search(_this.page);
		             }
    			});
    		};
    		loaderScroll();
    		window.addEventListener('DOMContentLoaded',loaderScroll,false);
    		for(var i=0,o;o=formList[i++];)
    		{
    			for(var j=0,c;c=o.child[j++];)
    			{
    				 this.formList.push(c);
    			}
    		}
    		switch(this.listType)
			{
				case 'started':
				this.searchUrl='/bpms/approves/submit';
				break;
				case 'CC':
				this.searchUrl='/bpms/approves/cc';
				break;
				case 'pending':
				if(this.orpengding==0)
				{
					this.searchUrl='/bpms/approves/todo';
				}else
				{
					this.searchUrl='/bpms/approves/done';
				}
				break;
			}
			this.approveNum();
    		this.search();
    	},
    	data:function(){
    		return{
    			formList:[],
    			listType:'',
    			oIscoll:null,
    			oscreenIscoll:null,
    			searchBfalg:false,
    			status:'',
    			approveType:'',
    			keyword:'',
    			loadIcon:true,
    			dataList:[],
    			page:1,
    			noData:false,
    			cc_read:0,
    			orpengding:0,
    			searchUrl:''
    		};
    	},
    	watch:{
    		'listType':function(val){
    		},
    		cc_read:function(val){
    			this.cancelfn();
    		},
    		orpengding:function(val){
    			if(this.listType=='pending' &&  val==0)
				{
					this.searchUrl='/bpms/approves/todo';
				}
				if(this.listType=='pending' &&  val==1)
				{
					this.searchUrl='/bpms/approves/done';
				}
    			this.cancelfn();
    		},
    		keyword:function(){
    		    this.search();
    		}
    	},
    	methods:
    	{
    		search:function(spage){
    			
    			this.loadIcon=true;
    		 	var page=spage?(spage):1;
    		 	if(page==1){this.page=1;this.oIscoll.scrollTo(0,0,0,'relative')};
    		 	 var obj={
    		 	 	page:page,
					keyword:this.keyword,
					type:this.approveType,
					status:this.status
    		 	 },_this=this;
    		 	 
    		 	 if(this.listType=='pending' &&  this.orpengding==0){
    		 	 	delete obj.status;
    		 	 }
    		 	 if(this.listType=='CC')
    		 	 {
    		 	 	this.cc_read==1?(obj['is_read']=0):('')
    		 	 }
    		 	 console.log(obj);
    		 	 this.myAjax({
	 	 		 	 type:"get",
	 	 		 	 tooken:false,
	 	 		 	 url:_this.searchUrl,
	 	 		 	 data:obj,
	 	 		 	 callback:function(data)
	 	 		 	 { 
	 	 		 	 	_this.loadIcon=false;
	 	 		 	 	/*if(data.data.count>=20){
	 	 		 	 		_this.clickLoad=true;
	 	 		 	 	}*/
	 	 		 	 	
	 	 		 	 	if(page==1 || !page)
	 	 		 	 	{
	 	 		 	 		_this.dataList=data.data.list;
	 	 		 	 	  
	 	 		 	 	}else
	 	 		 	 	{   
	 	 		 	 		for(var i=0;i<data.data.list.length;i++)
	 	 		 	 		{
	 	 		 	 			 _this.dataList.push(data.data.list[i]);
	 	 		 	 		}
	 	 		 	 	};
	 	 		 	    _this.$nextTick(function(){
	 	 		 	    	this.oIscoll.refresh();
	 	 		 	    });
	 	 		 	     if(_this.dataList.length<data.data.count && data.data.list.length==0)
	 	 		 	     {
	 	 		 	     	_this.page-=1;
	 	 		 	     }
	 	 		 	 	if(_this.dataList.length>=data.data.count)
	 	 		 	 	{
	 	 		 	 		_this.noData=true;
	 	 		 	 	}else{
	 	 		 	 		_this.noData=false;
	 	 		 	 	}
		 	 		 }
	 	 		 });
    		},
    		screenFn:function(e){
    			$("#screen_div").popup();
    			this.oscreenIscoll=new IScroll('#screen_div_list',{mouseWheel: true });
    			e.cancelBubble = true;
    		},
    		tyleRadiofn:function(type){
    			 this.approveType=type;
    		},
    		statusRadioFn:function(type){
    			this.status=type;
    		},
    		cancelfn:function(e){
    			var _this=this;
    			this.approveType='';
    			this.status='';
    			if(this.keyword){
    				this.keyword='';
    			}else{
    				this.search();
    			}
    			this.searchBfalg=false;
    		},
    		defaultfn:function(e){
    			e.preventDefault();
    		},
    		sureScreenFn:function(){
    			this.search();
    			$.closePopup();
    		},
    		newDing:function(e){
    			e.cancelBubble=true;
    			dd.ready(function(){
    				 dd.biz.ding.create({
	    					"users":[],
	    					"type":2,
	    					"alertType":2,
	    					"alertDate":{"format":"yyyy-MM-dd HH:mm","value":"2017-08-09 08:00"},
	    					"text":"钉正文内容",
	    					"bizType":1,
	    					"confInfo":{
	    						"bizSubType":2,
	    					    "startTime":{"format":"yyyy-MM-dd HH:mm","value":"2017-08-09 08:00"},
	    					    "endTime":{"format":"yyyy-MM-dd HH:mm","value":"2017-12-09 08:00"},
	    					    "remindMinutes":180,"remindType":2
	    					},
	    					"taskInfo":{
	    						"ccUsers":["userId3","userId4"],
	    					    "deadlineTime":{"format":"yyyy-MM-dd HH:mm","value":"2017-12-09 08:00"},
	    					    "taskRemind":180
	    					},
	    					"corpId":sessionStorage.getItem('corpId'),
	    					"onSuccess": function(data) {
						         
						    },
						    "onFail": function(){}   
	    			})
    			})
    		},
    		toApproveMsg:function(obj){
    		 	 var _this=this;
    			 if(this.type=='CC' && obj.is_read==0){
    		 	 	  this.myAjax({
		 	 		 	 type:"get",
		 	 		 	 tooken:false,
		 	 		 	 url: '/bpms/approves/read?process_instance_id='+obj.process_instance_id,
		 	 		 	 callback:function(data)
		 	 		 	 {
		 	 		 	 	 if(data.code=='200')
		 	 		 	 	 {
		 	 		 	 	 	obj.is_read=1;
		 	 		 	 	 };
		 	 		 	 	 _this.approveNum();
		 	 		 	 }
		 	 		 });
    		 	}
    		 	 if(obj.url)
    		 	 {
		 	 		dd.ready(function(){
		 	 			    dd.biz.util.openLink({
							    url:obj.url,
							    onSuccess : function(result) {
							    },
							    onFail : function(err) {}
							})
		 	 		});
    		 	 }
    		}
    	}
    };
    return {
        app:App       
    };
});